<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>10canvas折线图-绘制坐标系</title>
</head>
<style>
    canvas {
        border: 1px solid #ccc;
    }
</style>
<body>
<canvas width="600" height="400"></canvas>
<script>
    var myCanvas = document.querySelector('canvas');
    var ctx = myCanvas.getContext('2d');
    /*1.绘制坐标系*/
    /*2.确定原点*/
    /*3.确定距离画布旁边的距离*/
    var space = 20;
    /*4.确定坐标轴的长度*/
    /*5.确定箭头的大小 是个等腰三角形 10*/
    var arrowSize = 10;
    /*6.绘制箭头填充*/
    /*计算原点位置*/
    var canvasWidth = ctx.canvas.width;
    var canvasHeight = ctx.canvas.height;
    var x0 = space;
    var y0 = canvasHeight - space;
    /*绘制X轴*/
    ctx.beginPath();
    ctx.moveTo(x0 + 0.5, y0 - 0.5);
    ctx.lineTo(canvasWidth - space, y0 - 0.5);
    /*绘制箭头*/
    ctx.lineTo(canvasWidth - space - arrowSize, y0 - 0.5 -arrowSize/2);
    ctx.lineTo(canvasWidth - space - arrowSize, y0 - 0.5 +arrowSize/2);
    ctx.lineTo(canvasWidth - space, y0 - 0.5);
    ctx.fill();
    ctx.stroke();
    /*绘制y轴*/
    ctx.beginPath();
    ctx.moveTo(x0 + 0.5, y0 - 0.5);
    ctx.lineTo(x0 + 0.5, space);
    /*绘制箭头*/
    ctx.lineTo(x0 + 0.5 + arrowSize/2, space + arrowSize);
    ctx.lineTo(x0 + 0.5 - arrowSize/2, space + arrowSize);
    ctx.lineTo(x0 + 0.5, space);
    ctx.fill();
    ctx.stroke();
</script>
</body>
</html>

